package com.crm.service.saling.impl;

import com.crm.dao.saling.ContractDaoInterface;
import com.crm.pojo.Contract;
import com.crm.service.saling.AdvanceSearchService;
import com.crm.vo.ContractVO;
import com.crm.vo.icontractVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by dr5hx on 2018/8/31
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class AdvanceSearchServiceImpl implements AdvanceSearchService {
    @Autowired
    private ContractDaoInterface contractDaoInterface;

    @Override
    public List<ContractVO> contractAdvanceSearch(String contractTopic, Date orderStartTime, Date orderOverTime, String cName, String eName, String planName) {
        List<icontractVO> list = contractDaoInterface.contractAdvanceSearch("%" + contractTopic + "%", orderStartTime, orderOverTime, "%" + cName + "%", "%" + eName + "%", "%" + planName + "%");
        List<ContractVO> contractVOList = new ArrayList<>();
        for (icontractVO i : list) {
            Contract contract = new Contract();
            ContractVO contractVO = new ContractVO();
            contract.setContractId(i.getContractId());
            contract.setContractAccessory(i.getContractAccessory());
            contract.setContractAddress(i.getContractAddress());
            contract.setContractCheck(i.getContractCheck());
            contract.setContractCustomer(i.getContractCustomer());
            contract.setContractDoTime(i.getContractDoTime());
            contract.setContractEmpno(i.getContractEmpno());
            contract.setContractIsDel(i.getContractIsDel());
            contract.setContractIsRefund(i.getContractIsRefund());
            contract.setContractMoney(i.getContractMoney());
            contract.setContractNumber(i.getContractNumber());
            contract.setContractRemark(i.getContractRemark());
            contract.setContractState(i.getContractState());
            contract.setContractTopic(i.getContractTopic());
            contract.setFkCustomerId(i.getFkCustomerId());
            contract.setFkPlanId(i.getFkPlanId());
            contract.setOrderBackMoney(i.getOrderBackMoney());
            contract.setOrderOverTime(i.getOrderOverTime());
            contract.setOrderStartTime(i.getOrderStartTime());
            contractVO.setContract(contract);
            contractVO.setCname(i.getcName());
            contractVO.seteName(i.geteName());
            contractVO.setPlanName(i.getPlanName());
            contractVOList.add(contractVO);
        }
        return contractVOList;
    }
}
